var prefix = '/sys/dict/type';
$().ready(function () {
    validateRule();
});

$.validator.setDefaults({
    submitHandler: function () {
        save();
    }
});

function save() {
    $.ajax({
        cache: true,
        type: "POST",
        url: prefix + "/save",
        data: $('#dictTypeForm').serialize(), // 你的formid
        async: false,
        error: function () {
            parent.layer.alert("网络超时");
        },
        success: function (data) {
            if (data.code === 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            } else {
                parent.layer.alert(data.msg)
            }

        }
    });

}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#dictTypeForm").validate({
        rules: {
            typeName: {
                required: true
                , remote: {
                    url: prefix + "/exit",     //后台处理程序
                    type: "post",               //数据发送方式
                    dataType: "json"          //接受数据格式

                }
            }
            , typeValue: {
                required: true
                , remote: {
                    url: prefix + "/exit",     //后台处理程序
                    type: "post",               //数据发送方式
                    dataType: "json"           //接受数据格式
                }
            }
        },
        messages: {
            typeName: {
                required: icon + "类型名称不能为空"
                , remote: icon + "类型名称已存在"
            }
            , typeValue: {
                required: icon + "类型标识符不能为空"
                , remote: icon + "类型标识符已存在"
            }
        }
    })
}
